package dp.gr03.payroll.generalTransactions;

import dp.gr03.payroll.exception.PayRollException;
import dp.gr03.payroll.methods.HoldMethod;
import dp.gr03.payroll.payrollApplication.Transaction;
import dp.gr03.payroll.payrollDatabase.PayrollDatabase;
import dp.gr03.payroll.payrollDomain.Employee;
import dp.gr03.payroll.payrollDomain.PaymentClassification;
import dp.gr03.payroll.payrollDomain.PaymentSchedule;

public abstract class AddEmployeeTransaction implements Transaction
{

    protected int employeeId;
    protected String employeeAddress;
    protected String employeeName;
    protected PayrollDatabase db;
    protected Employee employeeToAdd;

    public AddEmployeeTransaction(int id, String name, String address)
    {
        this.db = PayrollDatabase.getInstance();

        this.employeeId = id;
        this.employeeName = name;
        this.employeeAddress = address;
    }

    @Override
    public final void execute() throws PayRollException
    {
        if(db.employeeExists(employeeId)){
            throw new PayRollException("This user ID already exists.");
        }
        employeeToAdd = new Employee(employeeId, employeeName, employeeAddress);
        employeeToAdd.setPaymentMethod(new HoldMethod());
        employeeToAdd.setPaymentSchedule(getPaymentSchedule());
        employeeToAdd.setPaymentClassification(getClassification());
        
        db.addEmployee(employeeToAdd);
    }
    
    protected abstract PaymentSchedule getPaymentSchedule();
    protected abstract PaymentClassification getClassification();
    

}
